//
//  E_1ViewController.m
//  RACExamale
//
//  Created by cym_bj on 2017/12/1.
//  Copyright © 2017年 com.cym. All rights reserved.
//

#import "E_1ViewController.h"
#import <ReactiveObjC/ReactiveObjC.h>
#import <ReactiveObjC/RACReturnSignal.h>
@interface E_1ViewController ()

@end

@implementation E_1ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title=@"映射(flattenMap,Map)";
    
    /*
     flattenMap，Map用于把源信号内容映射成新的内容。
     
     */
   
   // [self flattonMap01];
    //[self flattonMap02];
    [self map];
    
    
    
    
}
#pragma mark -用于信号中的信号
-(void)flattonMap01
{
    
    //flattonMap:用于信号中信号
    RACSubject *signalOfSignals=[RACSubject subject];
    
    RACSubject *signal=[RACSubject subject];
    
    [[signalOfSignals flattenMap:^__kindof RACSignal * _Nullable(id  _Nullable value) {
        
        NSLog(@"~%@",value);
        return value;
    }] subscribeNext:^(id  _Nullable x) {
        
        NSLog(@"x=%@",x);
    }];
    
    //发送信号
    [signalOfSignals sendNext:signal];
    [signal sendNext:@"213"];
    
}
#pragma mark - 数据处理
-(void)flattonMap02
{
    RACSubject *subject=[RACSubject subject];

    RACSignal *signal=[subject flattenMap:^__kindof RACSignal * _Nullable(id  _Nullable value) {
        
        value=[NSString stringWithFormat:@"哈哈:%@",value];
        return [RACReturnSignal return:value];
        
    }];
    
    [signal subscribeNext:^(id  _Nullable x) {
       
        NSLog(@"订阅信号：=%@",x);
    }];
    
    //发送数据
    [subject sendNext:@"名字"];
    
}
-(void)map
{
    RACSubject *subject=[RACSubject subject];
    RACSignal *signal=[subject map:^id _Nullable(id  _Nullable value) {
       
        //返回的类型，就是你需要映射的值
        return [NSString stringWithFormat:@"哈哈:=%@",value];
    }];
    
    [signal subscribeNext:^(id  _Nullable x) {
       
        NSLog(@"%@",x);
    
    }];
    
    
    [subject sendNext:@"133"];
    [subject sendNext:@"dddd"];
    
    
}


@end
